Learn R Programming

R.oo (version 1.2.7)

DOLLAR< -.Object: Makes the fields and methods of an Object assignable via the $<- and the [[<- operator

Description

Makes the fields and methods of an Object assignable via the $<- operator. This method is never called explicitly, but through an indirect usage of the $<- operator, e.g. obj$name <- "foo". 1) This method will first search for a set() method, e.g. if name has the value "age", a setAge() will be looked for. If such a method exists it will be called with the Object as the first argument and value as the second, e.g. setAge(this, value). A set() is only looked for if is a non-private field. A private field is a name beginning with a . (period). The rational for this naming convention is to be consistent with how ls() works, which will not list such members by default. Moreover, excluding private fields for the search of a set() will decrease the overhead for such field. 2) If no such method exists the value will be assigned to an existing field named name, if such exists. 3) Otherwise, the value will be assigned to a static field, if such exists. 4) In all other case, the value is assigned to a new field. Because any set() is called first, it is possible to encapsulate (hide away) fields with certain names or to put restrictions to what values can be assigned to them.

Usage

"$<-.Object"(this, name, value)
  "[[<-.Object"(this, name, value)

Arguments

name
The name of the set() method or the name of the field to be assigned the new value.
value
The value to be assigned.

Value

  • Returns itself, i.e. this, as all $<- methods must do.

See Also

For more information see Object.

Examples

Run this code
For a complete example see help(Object).

Run the code above in your browser using DataLab